package edu.midir.demo.pojo;

import edu.midir.demo.pojo.enumeration.CommonEnum;




/**
 * @author yz
 *
 */
public class ResultBean<T>  {
	private Boolean success;
	private String code="0000";
	private String msg;
	protected T data;

	public ResultBean() {
	}

	private ResultBean(boolean success, String code, String msg, T data) {
		this.success=success;
		this.code=code;
		this.data = data;
		this.msg = msg;
	}

	public ResultBean(boolean success, String code, T data) {
		this(success, code,null,data);
	}
	public ResultBean(boolean success, T data) {
		this.success=success;
		this.data=data;
	}
	public static<Q> ResultBean<Q> success(String code, String msg, Q data) {
		return new ResultBean<>(true,code,msg,data);
	}
	public static<Q> ResultBean<Q> success(String code, String msg) {
		return new ResultBean<>(true,code,msg,null);
	}
	public static<Q> ResultBean<Q> success(String code, Q data) {
		return success(code,null,data);
	}
	public static<Q> ResultBean<Q> success(Q data) {
		return success("0000",data);
	}
	public static<Q> ResultBean<Q> ok(String msg) {
		return success("0000",msg);
	}
	public static<Q> ResultBean<Q> fail(String code, String msg) {
		return new ResultBean<>(false,code,msg,null);
	}
	public static<Q> ResultBean<Q> fail(int code,String msg) {
		return new ResultBean<>(false, String.valueOf(code),msg,null);
	}
	public static<Q> ResultBean<Q> failFromEnum(CommonEnum commonEnum) {
		return new ResultBean<>(false,commonEnum.getCode(),commonEnum.getMsg(),null);
	}

//	public static<Q> ResultBean<Q> failWithEnum(Enum) {
//		return new ResultBean<>(false,String.valueOf(code),null,errorMsg,null);
//	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


}